<?php
// use the dPFramework to have easy database operations (store, delete etc.) by using its ObjectOrientedDesign
// therefore we have to create a child class for the module einstein

// a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework

/**
 *	@package dotProject
 *	@subpackage modules
 *	@version $Revision: 1.0 $
*/

// include the powerful parent class that we want to extend for einstein
require_once( $AppUI->getSystemClass ('dp' ) );		// use the dPFramework for easy inclusion of this class here

/**
 * The Sequence Class
 */
class CSequence extends CDpObject {
	// link variables to the einstein object (according to the existing columns in the database table einstein)
	var $seq_id = NULL;	//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality
	var $seq_key = NULL;
	var $seq_value = NULL;	
	var $seq_year = NULL;	

	// the constructor of the CEinstein class, always combined with the table name and the unique key of the table
	function CSequence() {
		$this->CDpObject( 'sequences', 'seq_id' );
	}
	function useValue(){
		$value = $this->seq_value++;
		$this->store();
		return $value;									
	}
	function loadByField(){
		$q = new DBQuery();
		$q->addTable($this->_tbl);
		if($this->seq_key!= null)
			$q->addWhere('seq_key = \''.$this->seq_key.'\'');
		if($this->seq_year!= null)
			$q->addWhere('seq_year = \''.$this->seq_year.'\'');
		$sql = $q->prepare();
		if(!db_loadObject($sql, $this, false, true)){
			$this->seq_value = 1;
			$this->store();
		}
				
	}				
}
		
?>